//
//  FinishTopView.m
//  51易借
//
//  Created by 张睿 on 2017/8/31.
//  Copyright © 2017年 张睿. All rights reserved.
//

#import "FinishTopView.h"

@interface FinishTopView ()
@property (nonatomic,strong)NSArray * btns;
@property (nonatomic,strong)NSArray * labels;
@property (nonatomic,strong)NSArray * progressViews;
@property (nonatomic, weak)UILabel * contactLabel;
@property (nonatomic, weak)UILabel * zhimaLabel;
@property (nonatomic, strong)UIImageView * oneImageView;
@property (nonatomic, strong)UIImageView * twoImageView;
@property (nonatomic, strong)UIImageView * threeImageView;
@property (nonatomic, strong)UIImageView * fourImageView;
@property (nonatomic, strong)UIImageView * fiveImageView;
@property (nonatomic, strong)UIImageView * sixImageView;
@property (nonatomic, strong)UIButton * oneButton;
@property (nonatomic, strong)UIButton * twoButton;
@property (nonatomic, strong)UIButton * threeButton;
@property (nonatomic, strong)UIButton * fourButton;
@property (nonatomic, strong)UIButton * fiveButton;
@property (nonatomic, weak)UILabel * proselfLabel;
@property (nonatomic, weak)UILabel * bankCardLabel;
@property (nonatomic, weak)UILabel * moveLabel;


@end

@implementation FinishTopView


- (instancetype)initWithFrame:(CGRect)frame{
    
    if ([super initWithFrame:frame]) {
        
        self.backgroundColor = [UIColor whiteColor];
        [self setupUI];
    }
    
    return self;
}


- (void)setupUI{
    
    UILabel * contactLabel = [UILabel new];
    
//    contactLabel.font = [UIFont fontWithName:TYPE_FACE size:11 * SCREENH6];
    contactLabel.font = [UIFont systemFontOfSize:11.5 * SCREENH6];
    contactLabel.textColor = ColorWithRGB(0x7f7f7f);
    contactLabel.text = @"紧急联系人";
    
    self.contactLabel = contactLabel;
    
    [self addSubview:self.contactLabel];
    
    
    UILabel * zhimaLabel = [UILabel new];
    
//    zhimaLabel.font = [UIFont fontWithName:TYPE_FACE size:11 * SCREENH6];
    zhimaLabel.font = [UIFont systemFontOfSize:11.5 * SCREENH6];
    zhimaLabel.textColor = ColorWithRGB(0x7f7f7f);
    zhimaLabel.text = @"芝麻授信";
    
    self.zhimaLabel = zhimaLabel;
    
    [self addSubview:self.zhimaLabel];
    
    
    self.oneImageView = [self setupImageViewWith:@"进度条"];
    
    [self addSubview:self.oneImageView];
    self.oneButton = [self setupButtonWithBackImage:@"完善资料-进度点" SelectImage:@"完善资料-进度点1" title:@"1"];
    
    [self addSubview:self.oneButton];
    
    self.twoImageView = [self setupImageViewWith:@"进度条"];
    
    [self addSubview:self.twoImageView];
    
    self.twoButton = [self setupButtonWithBackImage:@"完善资料-进度点"  SelectImage:@"完善资料-进度点1" title:@"2"];
    
    [self addSubview:self.twoButton];
    
    self.threeImageView = [self setupImageViewWith:@"进度条"];
    
    [self addSubview:self.threeImageView];
    
    self.threeButton = [self setupButtonWithBackImage:@"完善资料-进度点"  SelectImage:@"完善资料-进度点1" title:@"3"];
    
    [self addSubview:self.threeButton];
    
    self.fourImageView = [self setupImageViewWith:@"进度条"];
    
    [self addSubview:self.fourImageView];
    
    self.fourButton = [self setupButtonWithBackImage:@"完善资料-进度点"  SelectImage:@"完善资料-进度点1" title:@"4"];
    
    [self addSubview:self.fourButton];
    
    self.fiveImageView = [self setupImageViewWith:@"进度条"];
    
    [self addSubview:self.fiveImageView];
    
    self.fiveButton = [self setupButtonWithBackImage:@"完善资料-进度点"  SelectImage:@"完善资料-进度点1" title:@"5"];
    
    [self addSubview:self.fiveButton];
    
    self.sixImageView = [self setupImageViewWith:@"进度条"];
    
    [self addSubview:self.sixImageView];
    
    UILabel * proselfLabel = [UILabel new];
    
//    proselfLabel.font = [UIFont fontWithName:TYPE_FACE size:11 * SCREENH6];
    proselfLabel.font = [UIFont systemFontOfSize:11.5 * SCREENH6];
    proselfLabel.textColor = ColorWithRGB(0x7f7f7f);
    proselfLabel.text = @"个人信息";
    
    self.proselfLabel = proselfLabel;
    
    [self addSubview:self.proselfLabel];
    
    
    UILabel * bankCardLabel = [UILabel new];
    
//    bankCardLabel.font = [UIFont fontWithName:TYPE_FACE size:11 * SCREENH6];
    bankCardLabel.font = [UIFont systemFontOfSize:11.5 * SCREENH6];
    bankCardLabel.textColor = ColorWithRGB(0x7f7f7f);
    bankCardLabel.text = @"绑定银行卡";
    
    self.bankCardLabel = bankCardLabel;
    
    [self addSubview:self.bankCardLabel];
    
    
    UILabel * moveLabel = [UILabel new];
    
//    moveLabel.font = [UIFont fontWithName:TYPE_FACE size:11 * SCREENH6];
    moveLabel.font = [UIFont systemFontOfSize:11.5 * SCREENH6];
    moveLabel.textColor = ColorWithRGB(0x7f7f7f);
    moveLabel.text = @"手机运营商";
    
    self.moveLabel = moveLabel;
    
    [self addSubview:self.moveLabel];

    self.labels = @[self.proselfLabel,self.contactLabel,self.bankCardLabel,self.zhimaLabel,self.moveLabel];
    self.progressViews = @[self.oneImageView,self.twoImageView,self.threeImageView,self.fourImageView,self.fiveImageView,self.sixImageView];
    self.btns = @[self.oneButton,self.twoButton,self.threeButton,self.fourButton,self.fiveButton];
}


- (void)layoutSubviews{

    [self.contactLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self).offset(15 * SCREENH6);
        make.centerX.mas_equalTo(self).offset(-60 * SCREENH6);
    }];

    [self.zhimaLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.contactLabel);
        make.centerX.mas_equalTo(self).offset(60 * SCREENH6);
    }];
    
    [self.oneImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self);
        make.leading.mas_equalTo(self);
        make.width.mas_equalTo(40 * SCREENH6);
        make.height.mas_equalTo(3 * SCREENH6);
    }];
    
    [self.oneButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.oneImageView.mas_trailing);
        make.centerY.mas_equalTo(self.oneImageView);
        make.width.height.mas_equalTo(23 * SCREENH6);
    }];
    
    [self.twoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.width.height.mas_equalTo(self.oneImageView);
        make.leading.mas_equalTo(self.oneButton.mas_trailing);
    }];
    
    [self.twoButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.width.height.mas_equalTo(self.oneButton);
        make.leading.mas_equalTo(self.twoImageView.mas_trailing);
    }];
    
    [self.threeImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.width.height.mas_equalTo(self.twoImageView);
        make.leading.mas_equalTo(self.twoButton.mas_trailing);
    }];
    
    [self.threeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.width.height.mas_equalTo(self.twoButton);
        make.leading.mas_equalTo(self.threeImageView.mas_trailing);
    }];
    
    [self.fourImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.width.height.mas_equalTo(self.threeImageView);
        make.leading.mas_equalTo(self.threeButton.mas_trailing);
    }];
    
    [self.fourButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.width.height.mas_equalTo(self.threeButton);
        make.leading.mas_equalTo(self.fourImageView.mas_trailing);
    }];
    
    [self.fiveImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.width.height.mas_equalTo(self.fourImageView);
        make.leading.mas_equalTo(self.fourButton.mas_trailing);
    }];
    
    [self.fiveButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.width.height.mas_equalTo(self.fourButton);
        make.leading.mas_equalTo(self.fiveImageView.mas_trailing);
    }];
    
    [self.sixImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.fiveButton.mas_trailing);
        make.height.mas_equalTo(3 * SCREENH6);
        make.trailing.mas_equalTo(self);
        make.centerY.mas_equalTo(self.fiveButton);
    }];
    
    [self.proselfLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.oneButton);
        make.top.mas_equalTo(self.oneButton.mas_bottom).offset(10 * SCREENH6);
    }];
    
    [self.bankCardLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.threeButton);
        make.centerY.mas_equalTo(self.proselfLabel);
    }];
    
    [self.moveLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.fiveButton);
        make.centerY.mas_equalTo(self.bankCardLabel);
    }];
}


- (UIImageView *)setupImageViewWith:(NSString *)name{
    
    UIImageView * imageView = [UIImageView new];
    
    imageView.image = [UIImage imageNamed:name];
    
    return imageView;
}


- (UIButton *)setupButtonWithBackImage:(NSString *)imageString  SelectImage:(NSString *)selectImageString title:(NSString *)title{
    
    UIButton * button = [UIButton new];
    //完善资料-进度点
    [button setBackgroundImage:[UIImage imageNamed:imageString] forState:UIControlStateNormal];
    [button setBackgroundImage:[UIImage imageNamed:selectImageString] forState:UIControlStateSelected];

    [button setTitle:title forState:UIControlStateNormal];
    button.userInteractionEnabled = NO;
    button.titleLabel.font = [UIFont systemFontOfSize:14 * SCREENH6];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
    return button;
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

-(void)setStep:(NSInteger)step
{
    _step = step;
    
    [self.btns enumerateObjectsUsingBlock:^(UIButton*  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {

            obj.selected = (idx<step);

    }];
    [self.labels enumerateObjectsUsingBlock:^(UILabel*  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
        obj.textColor = (idx<step)?ColorWithRGB(0x51d7dd):ColorWithRGB(0x7f7f7f);
        
    }];
    [self.progressViews enumerateObjectsUsingBlock:^(UIImageView*  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        obj.image = [UIImage imageNamed:(idx<=step)?@"进度条-1":@"进度条"];

    }];
}




@end
